package com.qiyun.dinghuohui.utils;

import com.qiyun.dinghuohui.common.CommonDataSets;

import java.util.Comparator;
import java.util.Map;

public class OrderSortDataBySum implements Comparator<Map<String, Object>> {

	private boolean isSum = false;

	public OrderSortDataBySum() {
	};

	public OrderSortDataBySum(boolean isSum) {
		this.isSum = isSum;
	}

	@Override
	public int compare(Map<String, Object> lhs, Map<String, Object> rhs) {
		try {
			int numOne = 0;
			int numTwo = 0;
			if (isSum) {
				numOne = CommonDataSets.getIntforString(lhs.get("sum").toString());
				numTwo = CommonDataSets.getIntforString(rhs.get("sum").toString());
			} else {
				numOne = CommonDataSets.getIntforString(lhs.get("mark").toString());
				numTwo = CommonDataSets.getIntforString(rhs.get("mark").toString());
			}
			if (numOne > numTwo) {
				return 1;
			} else if (numOne < numTwo) {
				return -1;
			} else {
				return 0;
			}
		} catch (Exception e) {
			// TODO: handle exception
		}
		return 0;
		
	}

}
